<template>
    <bi-form>
            <bi-form-item label="配置类型" >
                <bi-radio v-model="from" dir="column" :option="fromOption" />
            </bi-form-item>
            <bi-form-item label="文件名" v-if="from == 'user'"   >
                <bi-input v-model="filename" required />
            </bi-form-item>
            <bi-form-item label="备注" v-if="from == 'user'"  >
                <bi-input v-model="filecomment"  required />
            </bi-form-item>

        </bi-form>
</template>

<script>
export default{
    dialog:{
        title:'添加配置',
        width:500
    },
    data(){
        let fromOption  = [
            {label:'数据库',value:'database'},
            {label:'缓存',value:'cache'},
            {label:'自定义',value:'user'},
        ];

        return {
            fromOption,
            from:'user',
            filename:'',
            filecomment:''
        }
    },
    props:{
        app:String
    },
    methods:{
        dialogOk(){
            let filecomment = '';
            let filename = '';
            if (this.from == 'user'){

               if (this.filename == 'database' || this.filename == 'cache'){
                  this.$alert('不能输入 database 或 cache');
                  return false;
               }

               filename = this.filename;
               filecomment = this.filecomment;

               value = this.user;
            }else{
               value = this.from;

               if (this.from == 'database'){
                  filename = 'database';
                  filecomment = '数据库';
               }

               if (this.from == 'cache'){
                  filename = 'cache';
                  filecomment = '缓存';
               }

            }
 
            this.$ajax({
                url:this.$url({controller:'config',action:'addFile'}),
                data:{
                    app:this.app,
                    filename,
                    filecomment
                },
                success:(data)=>{
                    this.dialog.callback();
                    this.dialog.close();
                }
            });
            return false;
        }
    }
}
</script>